<?php

include("classes/categoria.php");

$_class = new categoria();

$cat	= $_GET["cat"];
$n1		= $_GET["n1"];
$n1id	= $_GET["n1"];
$n2		= $_GET["n2"];
$n3		= $_GET["n3"];
$n4		= $_GET["n4"];
$n5		= $_GET["n5"];
$n6		= $_GET["n6"];
$n7		= $_GET["n7"];


$dadoscat	= $_class->pega($cat);
$dadoscat1	= $_class->listan1("WHERE cat = '$cat' ",false,false);
$dadoscat2	= $_class->listan2("WHERE cat = '$cat' and n1='$n1'",false,false);
$dadoscat3	= $_class->listan3("WHERE cat = '$cat' and n1='$n1' and n2='$n2' ",false,false);
$dadoscat4	= $_class->listan4("WHERE cat = '$cat' and n1='$n1' and n2='$n2' and n3='$n3' ",false,false);
$dadoscat5	= $_class->listan5("WHERE cat = '$cat' and n1='$n1' and n2='$n2' and n3='$n3' and n4='$n4'",false,false);

$dadoscat6	= $_class->listan6("WHERE cat = '$cat' and n1='$n1' and n2='$n2' and n3='$n3' and n4='$n4' and n5 = '$n5'",false,false);

$dadoscat7	= $_class->listan7("WHERE cat = '$cat' and n1='$n1' and n2='$n2' and n3='$n3' and n4='$n4' and n5 = '$n5' and n6='$n6' ",false,false);

$dadoscat8	= $_class->listan8("WHERE cat = '$cat' and n1='$n1' and n2='$n2' and n3='$n3' and n4='$n4' and n5 = '$n5' and n6='$n6' and n7='$n7' ",false,false);



$url[0]		= "?modulo=categoria&acao=linhas&cat=$cat&n1=";
$url[1]		= "?modulo=categoria&acao=linhas&cat=$cat&n1=$n1&n2=";
$url[2]		= "?modulo=categoria&acao=linhas&cat=$cat&n1=$n1&n2=$n2&n3=";
$url[3]		= "?modulo=categoria&acao=linhas&cat=$cat&n1=$n1&n2=$n2&n3=$n3&n4=";
$url[4]		= "?modulo=categoria&acao=linhas&cat=$cat&n1=$n1&n2=$n2&n3=$n3&n4=$n4&n5=";
$url[5]		= "?modulo=categoria&acao=linhas&cat=$cat&n1=$n1&n2=$n2&n3=$n3&n4=$n4&n5=$n5&n6=";
$url[6]		= "?modulo=categoria&acao=linhas&cat=$cat&n1=$n1&n2=$n2&n3=$n3&n4=$n4&n5=$n5&n6=$n6&n7=";

?>

<script type="text/javascript">

	function apagarLista(id){
	//alert(id)
	executar("acao/categoria.php?id="+id+"&acao=apagaLista","",ReturnCadastro);
	}	
	
function listagem(){
	var html		= document.getElementById("listageCompleta");
	html.innerHTML="<img hspace=\"5\" src=\"images/loading2.gif\" align=\"left\">carregando, aguarde...";
	include("modulos/categoria/lista-categorias.php","cat=<?=$cat?>","listageCompleta");
	}


function cadastraLista(){
	//function xhSend(url,formu,funcao){
	xhSend("acao/categoria.php?acao=cadlista","forlista",ReturnCadastro);
	}
	function ReturnCadastro(){
		if(xhReq.readyState==4){
		//alert(xhReq.responseText);
		
		if(xhReq.responseText == 1){
			listagem();
		}else{
		alert(xhReq.responseText);		
		}
		
		}
	}

</script>

<h3>Categoria Principal:</h3>
<?=$dadoscat["titulo"]?>
<br>
<br>

<form action="" id="forlista" name="forlista" method="post">
<input type="hidden" name="cat" value="<?=$cat?>">
<fieldset>


<select name="n1" id="n1" style="width:400px" onChange="location.href='<?=$url[0]?>'+this.value" >
<option value="0">Finalizar...</option>
<?php
foreach($dadoscat1 as $n1){
?>
    <option value="<?=$n1["id"]?>" <?php if($n1["id"]==$n1id){echo "selected";} ?>><?=$n1["titulo"]?></option>
<? } ?>
</select>


<br>

<?php if($_GET["n1"]){ ?>

<select name="n2" id="n2" style="width:400px" onChange="location.href='<?=$url[1]?>'+this.value" >
<option value="0">Finalizar...</option>
<?php
foreach($dadoscat2 as $n1){
?>
    <option value="<?=$n1["id"]?>" <?php if($n1["id"]==$n2){echo "selected";} ?>><?=$n1["titulo"]?></option>
<? } ?>
</select>
<? } ?>


<br>

<?php if($_GET["n2"]){ ?>

<select name="n3" id="n3" style="width:400px" onChange="if(this.value != 0){location.href='<?=$url[2]?>'+this.value}" >
<option value="0">Finalizar...</option>
<?php
foreach($dadoscat3 as $n1){
?>
    <option value="<?=$n1["id"]?>" <?php if($n1["id"]==$n3){echo "selected";} ?>><?=$n1["titulo"]?></option>
<? } ?>
</select>

<? } ?>

<br>

<?php if($_GET["n3"]){ ?>
<select name="n4" id="n4" style="width:400px" onChange="location.href='<?=$url[3]?>'+this.value" >
<option value="0">Finalizar...</option>
<?php
foreach($dadoscat4 as $n1){
?>
    <option value="<?=$n1["id"]?>"  <?php if($n1["id"]==$n4){echo "selected";} ?>><?=$n1["titulo"]?></option>
<? } ?>
</select>
<? } ?>

<br>

<?php if($_GET["n4"]){ ?>
<select name="n5" id="n5" style="width:400px" onChange="location.href='<?=$url[4]?>'+this.value" >
<option value="0">Finalizar...</option>
<?php
foreach($dadoscat5 as $n1){
?>

<option value="<?=$n1["id"]?>" <?php if($n1["id"]==$n5){echo "selected";} ?>>
<?=$n1["titulo"]?>
</option>

<? } ?>
</select>
<? } ?>

<?php if($_GET["n5"]){ ?>
<select name="n6" id="n6" style="width:400px" onChange="location.href='<?=$url[5]?>'+this.value" >
<option value="0">Finalizar...</option>
<?php
foreach($dadoscat6 as $n1){
?>

<option value="<?=$n1["id"]?>" <?php if($n1["id"]==$n6){echo "selected";} ?>>
<?=$n1["titulo"]?>
</option>

<? } ?>
</select>
<? } ?>

<br>

<?php if($_GET["n6"]){ ?>
<select name="n7" id="n7" style="width:400px" onChange="location.href='<?=$url[6]?>'+this.value" >
<option value="0">Finalizar...</option>
<?php
foreach($dadoscat7 as $n1){
?>

<option value="<?=$n1["id"]?>" <?php if($n1["id"]==$n7){echo "selected";} ?>>
<?=$n1["titulo"]?>
</option>

<? } ?>
</select>
<? } ?>


<br>

<?php if($_GET["n7"]){ ?>
<select name="n8" id="n8" style="width:400px" >
<option value="0">Finalizar...</option>
<?php
foreach($dadoscat8 as $n1){
?>

<option value="<?=$n1["id"]?>" <?php if($n1["id"]==$n7){echo "selected";} ?>>
<?=$n1["titulo"]?>
</option>

<? } ?>
</select>
<? } ?>


<br>
<input type="button" onClick="javascript:cadastraLista();" class="button" value="Cadastrar linha">

</fieldset>

</form>
<br>
<br>
<br>
<br>
<div id="listageCompleta"></div>

<script type="text/javascript">listagem();</script>




